import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * taxRateService.js - 税率定义 service
 * @date: 2018-10-29
 */
import request from 'utils/request';
import { parseParameters, isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
var tenantId = getCurrentOrganizationId();

function texRateApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/taxs") : 'taxs';
}
/**
 * 查询平台级税率
 * @param {Object} params - 查询参数
 */


export function queryTaxRate(_x) {
  return _queryTaxRate.apply(this, arguments);
}
/**
 * 新增税率
 * @param {Object} params 新增税率
 */

function _queryTaxRate() {
  _queryTaxRate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(texRateApi()), {
              method: 'GET',
              query: parseParameters(params)
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryTaxRate.apply(this, arguments);
}

export function insertTaxRate(_x2) {
  return _insertTaxRate.apply(this, arguments);
}
/**
 * 修改平台级税率定义
 * @param {Object} params 修改参数
 */

function _insertTaxRate() {
  _insertTaxRate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(texRateApi()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _insertTaxRate.apply(this, arguments);
}

export function updateTaxRate(_x3) {
  return _updateTaxRate.apply(this, arguments);
}
/**
 * 查询税率定义明细
 * @param {Number} taxId 税率定义明细查询参数
 */

function _updateTaxRate() {
  _updateTaxRate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(texRateApi()), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateTaxRate.apply(this, arguments);
}

export function queryTaxRateInfo(_x4) {
  return _queryTaxRateInfo.apply(this, arguments);
}
/**
 * 查询税率引用明细
 * @param {Object} params 税率引用明细查询参数
 */

function _queryTaxRateInfo() {
  _queryTaxRateInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(taxId) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(texRateApi(), "/").concat(taxId)));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryTaxRateInfo.apply(this, arguments);
}

export function queryTaxRateDetail(_x5) {
  return _queryTaxRateDetail.apply(this, arguments);
}

function _queryTaxRateDetail() {
  _queryTaxRateDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(texRateApi(), "/").concat(params.taxId, "/refs"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryTaxRateDetail.apply(this, arguments);
}